package com.hzhr.iot.user.dao;

import com.hzhr.iot.user.dao.mapper.custom.ActionInRoleEntityCustomMapper;
import com.hzhr.iot.user.dao.mapper.generator.ActionInRoleEntityMapper;
import com.hzhr.iot.user.entity.ActionInRoleEntity;
import com.hzhr.iot.user.entity.ext.ActionInRoleEntityExt;
import com.hzhr.iot.user.queryModel.custom.ActionInRoleCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class ActionInRoleDao {
    @Autowired
    ActionInRoleEntityMapper actionInRoleEntityMapper;
    @Autowired
    ActionInRoleEntityCustomMapper actionInRoleEntityCustomMapper;

    public int insert(ActionInRoleEntity record) {
        if (record == null) return 0;
        int changeCount = actionInRoleEntityMapper.insert(record);
        return changeCount;
    }

    public int delete(ActionInRoleCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = actionInRoleEntityCustomMapper.delete(queryModel);
        return changeCount;
    }

    public int update(ActionInRoleEntity record) {
        if (record == null) return 0;
        int changeCount = actionInRoleEntityMapper.updateByPrimaryKey(record);
        return changeCount;
    }

    public ActionInRoleEntity selectEntity(ActionInRoleCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ActionInRoleEntityExt> extList = actionInRoleEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<ActionInRoleEntity> selectEntityList(ActionInRoleCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ActionInRoleEntityExt> extList = actionInRoleEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<ActionInRoleEntity> entityList = new ArrayList<>();
        for (ActionInRoleEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public ActionInRoleEntityExt selectExt(ActionInRoleCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ActionInRoleEntityExt> extList = actionInRoleEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<ActionInRoleEntityExt> selectExtList(ActionInRoleCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ActionInRoleEntityExt> extList = actionInRoleEntityCustomMapper.selectExt(queryModel);
        return extList;
    }

    public int selectCount(ActionInRoleCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = actionInRoleEntityCustomMapper.selectCount(queryModel);
        return count;
    }
}
